﻿using SyncFileCommon.Model;

namespace SyncFileOption
{
    public partial class FrmUser : Form
    {
        /// <summary>
        /// 系统已存在的用户列表
        /// </summary>
        public List<UserModel> UserList;

        /// <summary>
        /// 是否添加信息窗体
        /// </summary>
        public bool IsAdd { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName
        {
            get
            {
                return txtUserName.Text.Trim();
            }
            set
            {
                txtUserName.Text = value;
            }
        }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password
        {
            get
            {
                return txtPassword.Text;
            }
            set
            {
                txtPassword.Text = value;
            }
        }

        public FrmUser()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.FormBorderStyle = FormBorderStyle.FixedDialog;//设置边框为不可调节
            this.MaximizeBox = false; //取消最大化按键
            this.MinimizeBox = false; //取消最小化按键
            this.ShowInTaskbar = false;//不在任务栏显示多个窗体框
        }

        private void FrmUser_Load(object sender, EventArgs e)
        {
            if (!IsAdd)
            {
                txtUserName.Enabled = false;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text == "[All]")
            {
                MessageBox.Show("用户名非法");
                return;
            }
            if (UserList != null)
            {
                if (UserList.Find(m => m.UserName == UserName) != null)
                {
                    MessageBox.Show("用户已存在,无法重复添加");
                    return;
                }
            }
            this.DialogResult = DialogResult.OK;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
